package com.tongtong.middleware.blockchain.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.tongtong.middleware.blockchain.entity.TblMiddlewareLog;
import com.tongtong.middleware.blockchain.mapper.TblMiddlewareLogMapper;
import com.tongtong.middleware.blockchain.service.MiddlewareLogService;

import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wangqi
 */
@Service
@Slf4j
public class MiddlewareLogServiceImpl implements MiddlewareLogService {
	@Autowired
	TblMiddlewareLogMapper tblMiddlewareLogMapper;

	@Override
	public void updateAsyncInfo(String jobId, String asyncInfo) {
		UpdateWrapper<TblMiddlewareLog> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("response_job_id", jobId).set("response_async_info", asyncInfo);
		tblMiddlewareLogMapper.update(updateWrapper);
	}

	@Override
	public TblMiddlewareLog packEntity(String provider, String method, String requestInfo, String responseInfo, String responseErrorInfo, String responseJobId,
			String responseAsyncInfo) {
		TblMiddlewareLog tblMiddlewareLog = new TblMiddlewareLog(
				provider, method, requestInfo, responseInfo, responseErrorInfo, responseJobId, responseAsyncInfo);
		tblMiddlewareLog.setId(IdUtil.getSnowflakeNextId());
		return tblMiddlewareLog;
	}

	@Override
	public TblMiddlewareLog packEntityUpgrade(String provider, String method, String userId, String assetId, String originalRequest, String requestInfo,
			String responseInfo, String responseErrorInfo, String responseJobId, String responseAsyncInfo) {
		TblMiddlewareLog tblMiddlewareLog = new TblMiddlewareLog(
				provider, method, userId, assetId, originalRequest, requestInfo, responseInfo, responseErrorInfo, responseJobId, responseAsyncInfo);
		tblMiddlewareLog.setId(IdUtil.getSnowflakeNextId());
		return tblMiddlewareLog;
	}
}
